package grains

import (
	"fmt"
)

const testVersion = 1

// SquareError struct
type SquareError struct{}

// Square Error
func (e *SquareError) Error() string { return fmt.Sprintf("error") }

// Total
func Total() (squareSum uint64) {
	for i := 1; i < 65; i++ {
		squareSum += uint64(SquareLoop(i))
	}

	return
}

// Square
func Square(input int) (squareSum uint64, err error) {
	if input <= 0 || input > 64 {
		err = &SquareError{}
		return
	}
	squareSum = uint64(SquareLoop(input))
	return
}

// SquareLoop
func SquareLoop(input int) int {
	if input <= 1 {
		return 1
	}

	return SquareLoop(input-1) * 2
}
